1 #include "Book.h"
2
3 Book::Book()
4 {
5     bookID =
"";
6     title =
"";
7     author =
"";
8     publisher =
"";
9     publication =
0;
10     edition =
0;
11     bookCondition = good;
12     isSold =
false;
13 }

14
15 void
Book::setBook(const string& newBookID, const string& newTitle, const string& newAuthor, const string& newPublisher,
16     
int newPublication, int newEditon, int newCost, int newRetailPrice)
17 {
18     bookID = newBookID;
19     title = newTitle;
20     author = newAuthor;
21     publisher = newPublisher;
22     publication = newPublication;
23     edition = newEditon;
24     cost = newCost;
25     retailPrice = newRetailPrice;
26     bookCondition = good;
27 }

28
29 void
Book::addNewBook(istream& ins)
30 {
31         cout <<
"Name: ";
32         getline(ins, title);
33
34         cout <<
"Enter Id Number ";
35         getline(ins, bookID);
36
37         cout <<
"Enter author: ";
38         
//if (ins.peek() == '\n')
39         
// ins.ignore();
40         getline(ins, author);
41
42         cout <<
"Enter Publisher: ";
43         getline(ins, publisher);
44         
45         cout <<
"Enter Publication Year: ";
46         ins >> publication;
47
48         cout <<
"Enter edition number: ";
49         ins >> edition;
50
51         cout <<
"Enter cost: ";
52         ins >> cost;
53
54         cout <<
"Enter retail price: ";
55         ins >> retailPrice;
56
57         cout <<
"Enter Condition of the Book";
58         
int newCondition = -1;
59         
while (newCondition < 0 || newCondition > 3)
60         {
61             ins >> newCondition;
62             
if (newCondition == 0)
63                 bookCondition = excellent;
64             
else if (newCondition == 1)
65                 bookCondition = good;
66             
else if (newCondition == 2)
67                 bookCondition = fair;
68             
else if (newCondition == 3)
69                 bookCondition = poor;
70             
else
71                 cout <<
"Invalid Entry, Try Again. ";
72         }
73 }

74 string
Book::getBookID() const
75 {
76     
return bookID;
77 }

78
79 string
Book::getTitle() const
80 {
81     
return title;
82 }

83
84 string
Book::getAuthor() const
85 {
86     
return author;
87 }

88 string
Book::getPublisher() const
89 {
90     
return publisher;
91 }
92
93 condition Book::getCondition()
const
94 {
95     
return bookCondition;
96 }

97
98 int
Book::getPublication() const
99 {
100     
return publication;
101 }

102
103 int
Book::getEdition()const
104 {
105     
return edition;
106 }

107
108 int
Book::getCost() const
109 {
110     
return cost;
111 }

112
113 int
Book::getRetail()const
114 {
115     
return retailPrice;
116 }

117
118 void
Book::setBookID(const string& newID)
119 {
120     bookID = newID;
121 }

122
123 void
Book::setTitle(const string& newTitle)
124 {
125     title = newTitle;
126 }

127
128 void
Book::setAuthor(const string& newAuthor)
129 {
130     author = newAuthor;
131 }

132
133 void
Book::setPublisher(const string& newPublisher)
134 {
135     publisher = newPublisher;
136 }

137
138 void
Book::setCondition(condition& newCondition)
139 {
140     bookCondition = newCondition;
141 }

142
143 void
Book::setPublication(int newPublication)
144 {
145     publication = newPublication;
146 }

147
148 void
Book::setEdition(int newEdition)
149 {
150     edition = newEdition;
151 }

152
153 void
Book::setCost(int newCost)
154 {
155     cost = newCost;
156 }

157
158 void
Book::setRetailPrice(int newRetailPrice)
159 {
160     retailPrice = newRetailPrice;
161 }

162
163 void
Book::printBook() const
164 {
165     cout <<
"Book ID: " << bookID << endl;
166     cout <<
"Title: " << title << endl;
167     cout <<
"Author: " << author << endl;
168     cout <<
"Publisher: " << publisher << endl;
169     cout <<
"Published " << publication << endl;
170     cout <<
"Edition: " << edition << endl;
171     cout <<
"Condition: " << bookCondition << endl;
172
173     
if (isSold)
174         cout <<
"Sold to" << endl;
175     
else
176         cout <<
"In Stock" << endl;
177     cout << endl;
178
179 }

180
181 void
Book::printBookToFile(ofstream& out)
182 {
183     
out << bookID << " " << title << endl;
184     
out << author << endl;
185     
out << publisher << endl;
186     
out << publication <<" "<< edition << " "<< cost << " " << retailPrice << endl;
187     
out << endl;
188 }
189 Book::~Book()
190 {
191
192 }
193
194 istream&
operator >> (istream& ins, Book& tempBook)
195 {
196     tempBook.addNewBook(ins);
197     
return ins;
198 }


Gõ tìm kiếm nhanh...